// 引入此文件需自建如下内容：
// footerButtons
import { transferDataDetail } from '@/components/task/utils';
import { PLAN_TYPE } from '@/constants';
import { mapGetters } from 'vuex';

export default {
  props: {
    visible: {
      type: Boolean,
      default: false,
    },
    formInfo: {
      type: Object,
      default: () => ({}),
    },
    visibled: {
      type: Boolean,
      default: false,
    },
    hasEdit: {
      type: Boolean,
      default: false,
    },
    data: {
      type: Object,
      default: () => [],
    },
    detail: {
      type: Object,
      default: () => ({}),
    },
    logs: {
      type: Array,
      default: () => [],
    },
    form: {
      type: Object,
      default: () => ({}),
    },
    currStatus: {
      type: [String, Number],
      default: '',
    },
    processId: {
      type: [String, Number],
      default: '',
    },
    priceId: {
      type: [String, Number],
      default: '',
    },
    planType: {
      type: String,
      default: 'BP',
    },
    currentNode: {
      type: Object,
      default: () => ({}),
    },
  },
  data() {
    this.PLAN_TYPE = PLAN_TYPE;
    return {
      disabled: false,
    };
  },
  computed: {
    applicationState() {
      return this.$store.state.dictionary.dict['application'] || {};
    },
    productionPlaceOptions() {
      return this.$store.state.dictionary.dict['production_place'] || {};
    },
    // modelOptions() {
    //   return this.$store.state.dictionary.dict['plan_detail_model'] || {};
    // },
    applicationOptions() {
      return this.$store.state.dictionary.dict['application'] || {};
    },
    ...mapGetters(['spinning']),


    titleName() {
      const type = '价格变更';
      const node = this.currentNode.label;
      const status =
        this.hasEdit && this.currentNode.key !== 'PriceStart'
          ? '待办'
          : undefined;
      return [type, node, status].filter(item => item).join('-');
    },
    // processId() {
    //   return this.detail?.plan?.processId;
    // },
    // hasEdit() {
    //   return this.form.createUserId ===this.form.handleUserId ? false : true;
    // }, record.createUserId === record.handleUserId
    filterButtons() {
      if (this.hasEdit) return this.footerButtons;
      return this.footerButtons.filter(item => !item.auth);
    },
    footerButtons() {
      if (this.formData.isCurrentProcessor) {
        return [
          {
            key: 'submit',
            type: 'primary',
            label: '提交',
          },
          {
            key: 'retweet',
            label: '转他人处理',
            icon: 'retweet',
          },
          {
            key: 'close',
            label: '返回',
          },
        ];
      } else if (this.formData.isWithdraw) {
        return [
          {
            key: 'recall',
            label: '撤回',
          },
          {
            key: 'close',
            label: '返回',
          },
        ];
      } else {
        return [
          {
            key: 'close',
            label: '返回',
          },
        ];
      }
    },
  },
  watch: {
    visible: {
      handler(val) {
        if (!val) return;
        // console.log('oooooooooo', this.detail);
        const plan = this.detail?.plan || {};
        const timeRanges = [plan.startTime, plan.endTime];
        // console.log('timeRanges: ', timeRanges);
        // this.form = {
        //   salesOrganization: plan.salesOrganization || '',
        //   serialNumber: plan.serialNumber || '',
        //   name: plan.name || '',
        //   startTime: timeRanges,
        //   deadlineTime: plan.deadlineTime || null,
        // };

        // 初版明细
        const planDetailList = this.detail?.planDetailList || [];
        this.planDetailList = transferDataDetail(planDetailList, timeRanges);

        // 终版明细
        const endPlanDetailList = this.detail?.endPlanDetailList || [];
        if (!endPlanDetailList.length) return;
        this.endPlanDetailList = transferDataDetail(
          endPlanDetailList,
          timeRanges
        );
      },
      immediate: true,
    },
  },
  methods: {
    handleInputChange(e, text, record, index, key) {
      if (e === '') {
        record[key] = null;
      }
      record[key] = e;
    },
    submitCallback() {
      this.$confirm('确认提交？提交后基本信息不允许再修改！', '提交确认', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.getSubmit()
      }).catch((err) => {
        console.log(err);
      });
    },
  },
};
